package com.huaxin.hxcloud.activity;

import com.huaxin.common.BaseActivity;

/**
 * Created by Administrator on 2016/11/16.
 */
public class SettingActivity extends BaseActivity {


/*//    @BindView(R.id.more)
//    ImageView more;
//    @BindView(R.id.toolbar)
//    Toolbar toolbar;
    @BindView(R.id.tb_save_pw)
    ToggleButton tbSavePw;
    @BindView(R.id.rl_save_pw)
    RelativeLayout rlSavePw;
    @BindView(R.id.tb_auto_login)
    ToggleButton tbAutoLogin;
    @BindView(R.id.rl_auto_login)
    RelativeLayout rlAutoLogin;
    @BindView(R.id.rl_notification_settings)
    RelativeLayout rlNotificationSettings;
    @BindView(R.id.tv_cache_size)
    TextView tvCacheSize;
    @BindView(R.id.rl_clean_cache)
    RelativeLayout rlCleanCache;
    @BindView(R.id.tb_double_click_exit)
    ToggleButton tbDoubleClickExit;
    @BindView(R.id.rl_double_click_exit)
    RelativeLayout rlDoubleClickExit;
    @BindView(R.id.setting_feedback)
    TextView settingFeedback;
    @BindView(R.id.rl_feedback)
    RelativeLayout rlFeedback;
    @BindView(R.id.rl_about)
    RelativeLayout rlAbout;
    @BindView(R.id.setting_logout)
    TextView settingLogout;
    @BindView(R.id.rl_exit)
    RelativeLayout rlExit;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initView() {
        super.initView();
//        setSupportActionBar(toolbar);
//        toolbar.setTitle("设置");
        tbSavePw.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
            @Override
            public void onToggle(boolean on) {
                PrefUtil.set(Constants.PK_SAVE_PW, on);
            }
        });
        tbAutoLogin.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
            @Override
            public void onToggle(boolean on) {
                PrefUtil.set(Constants.PK_AUTO_LOGIN, on);
            }
        });

//        tbDoubleClickExit.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
//            @Override
//            public void onToggle(boolean on) {
//                PrefUtil.set(Constants.PK_DOUBLE_CLICK_EXIT, on);
//            }
//        });


//        if (!BaseApp.app.isLogin()) {
//            settingLogout.setText("登出");
//        }

    }

    @OnClick({R.id.rl_notification_settings, R.id.rl_clean_cache, R.id.rl_double_click_exit, R.id.rl_about, R.id.rl_exit, R.id.rl_feedback})
    public void OnClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.rl_notification_settings:
                intent = new Intent(this, SettingNotificationActivity.class);
                startActivity(intent);
                break;
            case R.id.rl_clean_cache:
                cleanCache();
                break;
            case R.id.rl_feedback:
                intent = new Intent(this, FeedBackActivity.class);
                startActivity(intent);
                break;
            case R.id.rl_about:
                intent = new Intent(this, AboutActivity.class);
                startActivity(intent);
                break;
            case R.id.rl_exit:
//                MsgService.disconnectMqtt();
////                AppManager.getAppManager().backToActivity(LoginActivity.class);
//                //如果设置了登出，则可能是想切换帐号,将自动登录取消
//                PrefUtil.set(Constants.PK_AUTO_LOGIN,false);
//                intent=new Intent(this,LoginActivity.class);
//                startActivity(intent);
//                finish();
            default:
                break;
        }
    }

    @Override
    public void initData() {
        if (PrefUtil.get(Constants.PK_SAVE_PW, true)) {
            tbSavePw.setToggleOn();
        } else {
            tbSavePw.setToggleOff();
        }
        if (PrefUtil.get(Constants.PK_AUTO_LOGIN, true)) {
            tbAutoLogin.setToggleOn();
        } else {
            tbAutoLogin.setToggleOff();
        }

        if (PrefUtil.get(Constants.PK_DOUBLE_CLICK_EXIT, true)) {
            tbDoubleClickExit.setToggleOn();
        } else {
            tbDoubleClickExit.setToggleOff();
        }

        tvCacheSize.setText(DataCleanManager.getCacheFileSize(this));
    }

    public void cleanCache() {
        DialogUtil.getConfirmDialog(this, "是否清空缓存?", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                final ProgressDialog dialog = DialogUtil.getWaitDialog(SettingActivity.this, "请等待");
                AppOperator.runOnThread(new Runnable() {
                    @Override
                    public void run() {
                        DataCleanManager.cleanCacheFile(SettingActivity.this);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                tvCacheSize.setText(DataCleanManager.getCacheFileSize(SettingActivity.this));
                                dialog.dismiss();
                            }
                        });
                    }
                });

            }
        }).show();
    }*/


}
